#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<math.h>
#include<fcntl.h>
#include "p2p-file.h"
#include "p2p-config.h"


int main() {
    const char *file_path = FILE_;
    const char *file_path_hash = HASH_FILE;
    int size1, size2, fd1, fd2;
    struct stat stbuf;

    if (generate_hash_file(file_path) == -1) {
        printf("Error");
        exit(1);
    }

    fd1 = open(file_path, O_RDONLY);
    fstat(fd1, &stbuf);
    size1 = stbuf.st_size;
    close(fd1);

    fd2 = open(file_path_hash, O_RDONLY);
    fstat(fd2, &stbuf);
    size2 = stbuf.st_size;
    close(fd2);
    
    if ((size1 / PIECE_SIZE + !!(size1 % PIECE_SIZE)) != (size2 / SHA1_HASH_SIZE)) {
        printf("Hash file size incorrect\n");
        exit(1);
    }

    return 0;
}
